from functools import wraps
from flask_siwadoc import BaseModel, Blueprint

from swaager_init import siwa
from typing import Optional, Type

'''
class NewBlueprint(Blueprint):
    tags = []
    group = None

    def __init__(self, *args, **kwargs):
        if 'tags' in kwargs:
            self.tags = kwargs.pop('tags')
        if 'group' in kwargs:
            self.group = kwargs.pop('group')

        super().__init__(*args, **kwargs)

    def route(self,
              rule,
              *,
              query: Optional[Type[BaseModel]] = None,
              header: Optional[Type[BaseModel]] = None,
              cookie: Optional[Type[BaseModel]] = None,
              body: Optional[Type[BaseModel]] = None,
              form: Optional[Type[BaseModel]] = None,
              files=None,
              resp=None,
              x=[],
              tags=[],
              group=None,
              summary=None,
              description=None,
              ignore=False,
              **kwargs):

        # 忽略不使用 siwadoc 的接口
        if ignore:
            return super().route(rule, **kwargs)

        def decorator(func):
            view_func = siwa.doc(query,
                                 header,
                                 cookie,
                                 body,
                                 form,
                                 files,
                                 resp,
                                 x,
                                 tags or self.tags,
                                 group or self.group,
                                 summary,
                                 description)(func)
            view = self.__blueprint_route(view_func, rule, **kwargs)

            @wraps
            def inner(*args, **kwargs):
                return view(*args, **kwargs)

            return inner

        return decorator

    def __blueprint_route(self, view_func, rule, **kwargs):
        return super().route(rule, **kwargs)(view_func)
'''